﻿/*
 * @author: wizardc
 */

using UnityEngine;

namespace Dou.Extend
{
    /// <summary>
    /// Component 方法扩展
    /// </summary>
    public static class ComponentExtend
    {
        public static void SetActive(this Component component, bool active)
        {
            component.gameObject.SetActive(active);
        }

        public static void SetPosition(this Component component, float x, float y, float z)
        {
            component.transform.position = new Vector3(x, y, z);
        }

        public static void GetPosition(this Component component, out float x, out float y, out float z)
        {
            var position = component.transform.position;
            x = position.x;
            y = position.y;
            z = position.z;
        }

        public static void SetLocalPosition(this Component component, float x, float y, float z)
        {
            component.transform.localPosition = new Vector3(x, y, z);
        }
        
        public static void GetLocalPosition(this Component component, out float x, out float y, out float z)
        {
            var localPosition = component.transform.localPosition;
            x = localPosition.x;
            y = localPosition.y;
            z = localPosition.z;
        }
        
        public static void SetRotation(this Component component, float x, float y, float z)
        {
            component.transform.rotation = Quaternion.Euler(x, y, z);
        }

        public static void GetRotation(this Component component, out float x, out float y, out float z)
        {
            var eulerAngles = component.transform.rotation.eulerAngles;
            x = eulerAngles.x;
            y = eulerAngles.y;
            z = eulerAngles.z;
        }

        public static void SetLocalRotation(this Component component, float x, float y, float z)
        {
            component.transform.localRotation = Quaternion.Euler(x, y, z);
        }

        public static void GetLocalRotation(this Component component, out float x, out float y, out float z)
        {
            var localEulerAngles = component.transform.localRotation.eulerAngles;
            x = localEulerAngles.x;
            y = localEulerAngles.y;
            z = localEulerAngles.z;
        }

        public static void SetForward(this Component component, float x, float y, float z)
        {
            component.transform.forward = new Vector3(x, y, z);
        }

        public static void RotationWorld(this Component component, float x, float y, float z)
        {
            component.transform.Rotate(x, y, z, Space.World);
        }

        public static void RotationSelf(this Component component, float x, float y, float z)
        {
            component.transform.Rotate(x, y, z, Space.Self);
        }

        public static void SetLocalScale(this Component component, float x, float y, float z)
        {
            component.transform.localScale = new Vector3(x, y, z);
        }

        public static void GetLocalScale(this Component component, out float x, out float y, out float z)
        {
            var localScale = component.transform.localScale;
            x = localScale.x;
            y = localScale.y;
            z = localScale.z;
        }

        public static void DestroyComponent(this Component component, float delayTime = 0.0f)
        {
            Component.Destroy(component, delayTime);
        }
    }
}
